MAX_PARAMS=1000;

dim fp_names[MAX_PARAMS] = {{ "" }};
dim fp_values[MAX_PARAMS] = {{ 0.0 }};

nparams = 0;

trace_fd = -1;

proc onplot()
{
  fprintf(trace_fd, "%g\n", V[node_soma]);
};

proc load_params(fname)
{
	local fp, line, n, name, valstr, eindx;

	fp = fopen(fname, "r");
	
	while (fscanf(fp, "%s\n", line) != -1) {	
		eindx = strstr(line, "=");
		if (eindx >= 0) {		
			name = substr(line, 0, eindx);			
			valstr = substr(line, eindx+1, (strlen(line)-eindx-1));	
			
			fp_names[nparams] = name;
			fp_values[nparams] = atof(valstr);
			nparams++;			
		};
	};
};

func get_freeparam(name)
{
	for (k = 0; k < nparams; k++) {
		if (strcmp(fp_names[k], name) == 0)  return fp_values[k];
	};
	return UNINIT;
};

setvar();

if (notinit(id)) {
  fprintf(stderr, "ID not specified!\n");
  exit;
};
if (notinit(odir)) {
  fprintf(stderr, "Output directory not specified!\n");
  exit;
};
if (notinit(paramfile)) {
  fprintf(stderr, "Free parameter file path not specified!\n");
  exit;
};
if (notinit(samprate)) {
  fprintf(stderr, "Sampling rate not specified!\n");
  exit;
};

load_params(paramfile);

sprintf(fname, "%s/vtrace_%s.data", odir, id);
trace_fd = fopen(fname, "w");

if (trace_fd == 0) {
  fprintf(stderr, "Could not open '%s' for writing\n", fname);
  exit;
};

ploti = 1/samprate;

fprintf(stderr, "######### using nevo.n ##########\n");
fprintf(stderr, "# ID: %s\n", id);
fprintf(stderr, "# Free param file: %s\n", paramfile);
fprintf(stderr, "# Output Directory: %s\n", odir);
fprintf(stderr, "# Sampling Rate: %g Hz\n", samprate);
fprintf(stderr, "# Free Parameters (%g):\n", nparams);
for (k = 0; k < nparams; k++)  fprintf(stderr, "#      %s=%g\n", fp_names[k], fp_values[k]);
